<?php
	class nguoidungdb
	{
		public function Add($TenNguoiDung, $MaPhongBan, $MaChucVu, $DienThoai, $Email, $TenDangNhap, $MatKhau, $Khoa, $DiaChi)
		{
			$sql = "INSERT INTO `tbl_nguoidung`(`TenNguoiDung`, `MaPhongBan`, `MaChucVu`, `DienThoai`, `Email`, `TenDangNhap`, `MatKhau`, `Khoa`, `diaChi`)
			VALUES ('$TenNguoiDung', $MaPhongBan, $MaChucVu,'$DienThoai', '$Email', '$TenDangNhap', '$MatKhau', $Khoa,'$DiaChi')";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaNguoiDung)
		{
			$sql = "DELETE FROM `tbl_nguoidung` WHERE MaNguoiDung = $MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaNguoiDung, $TenNguoiDung, $DienThoai, $Email, $DiaChi)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `TenNguoiDung`='$TenNguoiDung', 
						`diaChi`='$DiaChi',
						`Email`='$Email',
						`DienThoai`='$DienThoai'
					WHERE `MaNguoiDung`=$MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function GetList($MaNguoiDung, $TenNguoiDung, $MaPhongBan, $MaChucVu, $DienThoai, $Email, $TenDangNhap, $MatKhau, $Khoa, $DiaChi)
		{
			$sql = " SELECT * FROM `tbl_nguoidung`,`tbl_chucvu`,`tbl_phongban`  WHERE tbl_nguoidung.MaChucVu = tbl_chucvu.MaChucVu AND tbl_nguoidung.MaPhongBan = tbl_phongban.MaPhongBan ";
			if($MaNguoiDung != 0)
				$sql .= " AND tbl_nguoidung.MaNguoiDung = $MaNguoiDung";
			
			if($TenNguoiDung != "")
				$sql .= " AND tbl_nguoidung.TenNguoiDung LIKE '%$TenNguoiDung%'";
			
			if($MaPhongBan != "")
				$sql .= " AND tbl_nguoidung.MaPhongBan = $MaPhongBan";
				
			if($MaChucVu != "")
				$sql .= " AND tbl_nguoidung.MaChucVu = '$MaChucVu'";
				
			if($DienThoai != "")
				$sql .= " AND tbl_nguoidung.DienThoai = '$DienThoai'";
				
			if($Email != "")
				$sql .= " AND tbl_nguoidung.Email = '$Email'";
				
			if($TenDangNhap != "")
				$sql .= " AND tbl_nguoidung.TenDangNhap = '$TenDangNhap'";
			if($MatKhau != "")
				$sql .= " AND tbl_nguoidung.MatKhau = '$MatKhau'";
				
			if($Khoa != "")
				$sql .= " AND tbl_nguoidung.Khoa = '$Khoa'";
				
			if($DiaChi != "")
				$sql .= " AND tbl_nguoidung.diaChi = '$DiaChi' ";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function ChangePass($MaNguoiDung, $MatKhau)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `MatKhau` = '$MatKhau'
					WHERE `MaNguoiDung` = $MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		
		public function Active($MaNguoiDung, $Khoa)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `Khoa` = $Khoa
					WHERE `MaNguoiDung` = $MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		public function ChangeChucVu($MaNguoiDung, $MaChucVu)
		{
			$sql = "UPDATE `tbl_nguoidung` 
					SET `MaChucVu`=$MaChucVu
					WHERE `MaNguoiDung`=$MaNguoiDung";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		
	
	}
?>